package Java测试.编码1copycopy;

//1.编写一个Worker类，为Worker类添加相应的代码，使得Worker对象能正确放入TreeSet中。并编写相应的测试代码。
//提示:
//1)Worker类含有name,age,salary三个属性
//2)取值，赋值的方法可省略
//3)比较时，先比较工人的年龄大小，年龄小的排在前面。如果两个工人年龄相同，则根据字典顺序比较工人姓名。
//4)编写测试类，向集合中添加三条数据
//5)遍历集合，输出集合中的元素信息(Worker类编写toString方法)
public class Worket implements Comparable<Worket>{
    @Override
    public int compareTo(Worket o) {
        int sum=o.getAge()-this.getAge();
        int i=(sum==0)?this.getName().compareTo(o.getName()):sum;
        return i;
    }

    private String name;
    private int age;
    private int salary;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getSalary() {
        return salary;
    }

    public void setSalary(int salary) {
        this.salary = salary;
    }

    public Worket(String name, int age, int salary) {
        this.name = name;
        this.age = age;
        this.salary = salary;
    }

    public Worket() {
    }
}
